package com.kbckbc.emailmemo;

import java.util.ArrayList;
import java.util.StringTokenizer;

import android.content.Context;
import android.content.res.Resources;

public class Memo {
	final static String TOKENNIZER = ";";
	final static int MAX_IMAGE_COUNT = 5;

	boolean checked;
	int _id;
	String content;
	String create_dttm;
	String modf_dttm;
	String tag;
	ArrayList<String> arrImagePath;
	String sync;

	Memo(boolean x, int a, String b, String c, String d, String e,
			ArrayList<String> f, String g) {
		_id = a;
		content = b;
		create_dttm = c;
		modf_dttm = d;
		if (e == null) {
			tag = "default";
		} else {
			tag = e;
		}
		arrImagePath = f;
		sync = g;
	}

	Memo(boolean x, int a, String b, String c, String d, String e, String f,
			String g) {
		_id = a;
		content = b;
		create_dttm = c;
		modf_dttm = d;
		if (e == null) {
			tag = "default";
		} else {
			tag = e;
		}
		arrImagePath = getArryListImagePathFromConcatenatedImagePath(f);
		sync = g;
	}

	String getCreateDttm() {
		return create_dttm.substring(0, 10);
	}

	String getModifyDttm() {
		return create_dttm.substring(0, 10);
	}

	ArrayList<String> getImagePathArrayList() {
		return arrImagePath;
	}

	public String getConcatenatedImagePath() {
		String result = "";

		for (int i = 0; i < arrImagePath.size(); i++) {
			result += arrImagePath.get(i);
			result += TOKENNIZER;
		}

		return result;
	}

	public String getContent(Context context) {
		String emailContent = "";

		emailContent += context.getString(R.string.share_email_content) + " ";
		emailContent += content;
		emailContent += "\n";
		emailContent += context.getString(R.string.share_email_sort_order1)
				+ " ";
		emailContent += create_dttm;
		emailContent += "\n";
		emailContent += context.getString(R.string.share_email_sort_order2)
				+ " ";
		emailContent += modf_dttm;
		emailContent += "\n";
		emailContent += "\n";

		return emailContent;

	}

	public String getSubject() {
		if (content.length() < 20) {
			return content;
		} else {
			return content.substring(1, 20);
		}
	}

	public String getSubject(Context context) {
		if (content.length() < 20) {
			return context.getString(R.string.share_email_subject) + " "
					+ content;
		} else {
			return context.getString(R.string.share_email_subject)
					+ content.substring(1, 20);
		}
	}

	public Integer getId() {
		return _id;
	}

	public static String getConcatenatedImagePath(ArrayList<String> path) {
		String result = "";

		for (int i = 0; i < path.size(); i++) {
			result += path.get(i);
			result += TOKENNIZER;
		}

		return result;
	}

	public static ArrayList<String> getArryListImagePathFromConcatenatedImagePath(
			String concatenatedImagePath) {
		ArrayList<String> result = new ArrayList<String>();

		if (concatenatedImagePath != null) {
			StringTokenizer st = new StringTokenizer(concatenatedImagePath,
					TOKENNIZER);
			while (st.hasMoreElements()) {
				result.add(st.nextElement() + "");
			}
		}

		return result;
	}
	
	public String getSync() {
		return sync;
		
	}
}
